<?php
switch ($_REQUEST['sAction']) {
	case 'user-attendancedelete':
		$iResult = UserHandler::delAttendance($_SESSION['rid'], $_REQUEST['iTiming']);
		if ($iResult == 1) {
			header('Location: index.php?sView=user-attendance');
			exit();
		}
		break;
	case 'user-attendanceadd':
		$iTiming = mktime((int)$_REQUEST['iHour'], (int)$_REQUEST['iMinute'], (int)$_REQUEST['iSecond'], (int)$_REQUEST['iMonth'], (int)$_REQUEST['iDay'], (int)$_REQUEST['iYear']);
		$iResult = UserHandler::addAttendance($_SESSION['rid'], $iTiming, $_REQUEST['sType']);
		if ($iResult > 0) {
			header('MiJob-Action: success');
			header('Location: index.php?sView=user-attendance');
			exit();
		}
		break;
	case 'user-add':
		$iResult = UserHandler::addUser($_REQUEST['sUser'], $_REQUEST['sPass'], $_REQUEST['sPassAgain'], $_REQUEST['sFullname'], $_REQUEST['sEmail'], $_REQUEST['bAdmin'], $_REQUEST['bAccountant']);
		if ($iResult > 0) {
			
			header('Location: index.php?sView=user-list');
			exit();
		}
		break;
	case 'user-change':
		$iResult = UserHandler::changeUser($_REQUEST['iUser'], $_REQUEST['sUser'], $_REQUEST['sPass'], $_REQUEST['sPassAgain'], $_REQUEST['sFullname'], $_REQUEST['sEmail'], $_REQUEST['bAdmin'], $_REQUEST['bAccountant']);
		if ($iResult == 1) {
			header('Location: index.php?sView=user-list');
			exit();
		}
		break;
	case 'user-delete':
		$iResult = UserHandler::delUser($_REQUEST['iUser']);
		if ($iResult == 1) {
			header('Location: index.php?sView=user-list');
			exit();
		}
		break;
	case 'user-login':
		$iResult = UserHandler::login($_REQUEST['sUser'], $_REQUEST['sPass']);
		if ($iResult > 0) {
			$_SESSION['rid'] = $iResult;
			$_SESSION['rip'] = $_SERVER['REMOTE_ADDR'];

			header('MiJob-Action: success');
			header('MiJob-SetLocalUserId: '.$iResult);
			if ($_REQUEST['sRequestURI']) {
				header('Location: '.urldecode($_REQUEST['sRequestURI']));
				exit();
			}
			else {
				if (@$_SESSION['oUserVars']['defaultjob']) {
					header('Location: index.php?sView=job-view&iJobID='.$_SESSION['oUserVars']['defaultjob']);
					exit();
				}
				else {
					header('Location: index.php?sView=job-list');
					exit();
				}
			}
		}
		break;
	case 'user-logout':
		session_destroy();
		header("Location: index.php?sView=user-login");
		exit();
		break;
}
?>
